<template>
  <el-container style="height: 100%; border: 1px solid #eee">
    <el-aside width="200px" style="background-color: rgb(238, 241, 246)">
      <el-affix :offset="0">
        <el-image
          style="width: 100%; height: 100px"
          :src="url"
          fit="cover"
          class="image"
        ></el-image>
      </el-affix>

      <el-menu
        :default-openeds="['0']"
        :default-active="$route.path"
        background-color="#545c64"
        text-color="#fff"
        router
        :collapse="isCollapse"
        style="width: 200px"
      >
        <el-submenu :index="i.toString()" v-for="(v, i) in menuList" :key="i">
          <template #title
            ><i class="iconfont"> &#xe606; </i>{{ v.menuName }}</template
          >
          <el-menu-item-group>
            <el-menu-item
              v-for="(m, n) in v.children"
              :key="n"
              :index="m.path.toString()"
              :route="m.path.toString()"
              >{{ m.menuName }}</el-menu-item
            >
          </el-menu-item-group>
        </el-submenu>
      </el-menu>
    </el-aside>

    <el-container>
      <el-header
        style="text-align: right; font-size: 12px"
        height="80px"
        class="header"
      >
        <Bread />

        <div>
          <el-dropdown>
            <span>{{ name }}</span> <i class="iconfont"> &#xe607; </i>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item @click="logout"> 退出</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
          <el-button type="success" round @click="allScreen" size="small"
            >全屏</el-button
          >
          <el-button type="success" round @click="zhedie" size="small"
            >折叠</el-button
          >
        </div>
      </el-header>

      <el-main style="background: f9f9f9">
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script setup>
import { getList } from "../api/Home";
import { useRouter } from "vue-router";
import { onMounted, reactive, ref } from "vue";
import Bread from "../components/Bread.vue";
import screenfull from "screenfull"; //全屏

const url = "../../public/img/攻克柏林.png";

let name = "未登录"; //用户名
const router = useRouter(); //使用

let menuList = reactive([]);
onMounted(() => {
  getList().then((res) => {
    res.forEach((v) => {
      menuList.push(v);
    });
  });
});

name = localStorage.getItem("user") ? localStorage.getItem("user") : "未登录";

let isCollapse = ref(false); //导航菜单是否折叠
const zhedie = () => {
  isCollapse.value = !isCollapse.value;
};
const allScreen = () => {
  //全屏
  screenfull.toggle();
};
const logout = () => {
  localStorage.removeItem("user");
  localStorage.removeItem("token");
  router.push("/login");
};
</script>
<style lang="scss">
html,
body,
#app,
.home {
  width: 100%;
  height: 100%;
}
*::-webkit-scrollbar {
  display: none;
}
.image {
  width: 100% !important;
}
.container {
  background-color: #f9f9f9;
}
img {
  width: 100%;
}
.header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .el-breadcrumb {
    flex: 1;
  }
}
.el-menu-item.is-active {
  color: 4445c64 !important;
}
</style>
